package net.ithe.mapper;

import net.ithe.pojo.Student;
import net.ithe.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {
    /**
     * 分页查询学生数据
     * @param studentQueryParam
     * @return
     */
    List<Student> list(StudentQueryParam studentQueryParam);
    /**
     * 批量删除学生数据
     * @param ids
     */
    void deleteByIds(List<Integer> ids);
    /**
     * 新增学生数据
     * @param student
     */
    @Insert("INSERT INTO student(name,no,gender,phone,id_card,is_college,address,degree,graduation_date,clazz_id,create_time,update_time)" +
            "values (#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{createTime},#{updateTime})")
    void insert(Student student);
    /**
     * 根据id查询学生数据
     * @param id
     */
    @Select("SELECT id, name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id, violation_count, violation_score, create_time, update_time FROM student WHERE id=#{id}")
    Student getById(Integer id);
    /**
     * 更新学生数据
     * @param student
     */
    @Update("UPDATE student SET " +
            "name=#{name},no=#{no},gender=#{gender},phone=#{phone},id_card=#{idCard},is_college=#{isCollege},address=#{address},degree=#{degree},graduation_date=#{graduationDate},clazz_id=#{clazzId}," +
            "violation_count=#{violationCount},violation_score=#{violationScore},update_time=#{updateTime} " +
            "WHERE id=#{id}")
    void update(Student student);
    /**
     * 更新学生违规次数和违规分数
     * @param student
     */
    @Update("UPDATE student SET " +
            "violation_count=#{violationCount},violation_score=#{violationScore} where id=#{id}")
    void updateViolation(Student student);

    /**
     * 统计学历数据
     * @return
     */
    List<Map<String, Object>> countDegreeData();
}
